﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.ApiProject.Area.SystemManager;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.DtoModel.SystemSettings.QualificationAdministration;
using SystemCenterSoa.PoModel.SystemSettings.QualificationAdministration;
using SystemCenterSoa.Service.SystemSettings.QualificationAdministration;

namespace SystemCenterSoa.ApiProject.Area.SystemSettings.QualificationAdministration
{
    [AllowAnonymous]
    public class DictionaryTableController : SystemManagerBaseController
    {
        private DictionaryTableService _dictionaryTableService;
        public DictionaryTableController(DictionaryTableService dictionaryTableService)
        {
            _dictionaryTableService = dictionaryTableService;
        }
        [HttpPost]
        public ResultModel<bool> DictionaryTableAdd(DictionaryTablePo info)
        {
            try
            {

                info.creator_date = DateTime.Now;
                info.creator_name = LoginUser.user_full_name;
                info.dt_status = 0;
                var data = _dictionaryTableService.DictionaryTableAdd(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }
        [HttpPost]
        public ResultModel<bool> DictionaryTableDelete(int id)
        {
            try
            {
                var data = _dictionaryTableService.DictionaryTableDelete(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }
        [HttpGet]
        public ResultModel<DictionaryTablePo> DictionaryTableEdit(int id)
        {
            try
            {
                var data = _dictionaryTableService.DictionaryTableEdit(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<DictionaryTablePo>(ex);
            }
        }
        [HttpPost]
        public ResultModel<bool> DictionaryTableUpdate(DictionaryTablePo info)
        {
            try
            {
                info.modifi_date = DateTime.Now;
                info.modifi_name = LoginUser.user_full_name;
                var data = _dictionaryTableService.DictionaryTableUpdate(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }
        [HttpPost]
        public ResultModel<PagerResult<DictionaryTableDto>> SearchPage(SearchModel sm)
        {
            try
            {
                var data = _dictionaryTableService.SearchPage(sm);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<PagerResult<DictionaryTableDto>>(ex);
            }


        }
        [HttpGet]
        public ResultModel<List<DictionaryTablePo>> DictionaryTableByTypeKey(string typeKey)
        {
            try
            {
                var data = _dictionaryTableService.DictionaryTableByTypeKey(typeKey);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<DictionaryTablePo>>(ex);
            }
        }
        [HttpGet]
        public ResultModel<List<DictionaryTypeTablePo>> BindType()
        {
            try
            {
                var data = _dictionaryTableService.BindType();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<DictionaryTypeTablePo>>(ex);
            }
        }
    }
}
